/****************************************
Figure A.10
*****************************************/

use "$dir/Data/Original/TotalMR_bystateyear.dta", clear

* Merge with population data
merge m:1 state decade using "$dir/Data/Original/US_States_Pop.dta"
drop _merge

sort state year decade
label var num_records "Total Number of Records"


/* Dividing States into regions */
gen region = ""

/***********************/
/****** North East ****/
/**********************/

replace region = "North East" if inlist(state, "Connecticut", ///
"Massachusetts", "Vermont", "Rhode Island", "Maine", "New Hampshire" )
replace region = "North East" if inlist(state, "New Jersey", "New York", ///
"Pennsylvania")

/*******************/
/****** Mid-West ***/
/********************/

replace region = "Midwest" if inlist(state, "Illinois", "Indiana", ///
"Michigan", "Ohio", "Wisconsin")
replace region = "Midwest" if inlist(state, "Iowa", "Kansas", ///
"Minnesota", "Missouri", "Nebraska", "North Dakota", "South Dakota")


/*********************/
/******* South ********/
/**********************/


replace region = "South" if inlist(state, "Delaware", "Florida", ///
"Georgia", "Maryland", "North Carolina", "South Carolina", "Virginia", ///
"West Virginia")
replace region = "South" if inlist(state, "Alabama", "Kentucky", ///
"Mississippi", "Tennessee", "Arkansas", "Louisiana", "Oklahoma", "Texas")

/*****************/
/***** West *****/
/******************/

replace region = "West" if inlist(state, "Arizona", "Colorado", ///
 "Idaho", "Montana", "Nevada", "New Mexico", "Utah", "Wyoming")
replace region = "West" if inlist(state, "Alaska", "California", ///
 "Hawaii", "Oregon", "Washington") 



/********************************
Figure A.10
********************************/

* Total Records
binscatter num_records year if year <= 1858, linetype(connect) ///
lcolors(black) ytitle("Total Records") xtitle("Year") msymbols(none)
graph save "$dir/Output/TablesFigures/MR_Total.gph", replace


preserve
collapse (mean) num_records pop, by(state decade region)

replace pop=  (pop[_n] + pop[_n+1])/2 /* conservative taking the avg of populations 10 year apart) */
gen pop_1000 = round(pop/1000)
gen marriages_p1000 = num_records/pop_1000

label var marriages_p1000 "Marriages per 1000 people"
drop if region == "West"

* Records per 1000 people
binscatter  marriages_p1000 decade if decade >= 1790 & decade <= 1858, linetype(connect) nquantiles(50)  ///
lcolors(black) ytitle("Marriages per 1000 people") xtitle("Year") ylabel(0(2)10) yline(10) msymbols(none)
graph save "$dir/Output/TablesFigures/MR_p1000.gph", replace

gr combine "$dir/Output/TablesFigures/MR_Total.gph" "$dir/Output/TablesFigures/MR_p1000.gph", title("")

graph export "$dir/Output/TablesFigures/Fig_MRCoverage.png", replace
